home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / netconf / start.c < prev    next >
C/C++ Source or Header  |  1996-08-03  |  6KB  |  198 lines

  1. /* #Specification: netconf / process management
  2.     All the rc's script in /etc/rc.d are week. They simply
  3.     start a bunch of daemon. If something goes wrong, they
  4.     generally continue to fire daemon after daemon. All this
  5.     is fragile.
  6.  
  7.     Instead, all this management is done using netconf. Netconf
  8.     will probe around to find out if a daemon must be started, if
  9.     there is enough configuration information for this daemon available.
  10.  
  11.     One goal is to allow netconf to "update" the daemon after
  12.     making some changes to the network configuration.
  13.  
  14.     For example, you edit /etc/exports and run netconf -update
  15.     after. It will kill mountd and start it again.
  16. */
  17. #include <stdlib.h>
  18. #include "netconf.h"
  19. #include "../dialog/dialog.h"
  20. #include "../xconf/xconf.h"
  21. #include "../dnsconf/dnsconf.h"
  22. #include "../fstab/fstab.h"
  23. #include "../askrunlevel/askrunlevel.h"
  24. #include "netconf.m"
  25.  
  26. /*
  27.     Start a daemon if it is not already started
  28.     Return -1 if any error.
  29. */
  30. int netconf_startstop(const char *name, int go)
  31. {
  32.     int ret = -1;
  33.     DAEMON *dae = daemon_find (name);
  34.     if (dae != NULL){
  35.         if(!dae->is_managed()){
  36.             /* #SpΘcification: netconf / daemons and commands / not managed
  37.                 The user may choose (advance feature) not to let netconf
  38.                 managed some command. This may severly break a system.
  39.                 Off course a user who do so is on his own. For example
  40.                 a user who decided to disable the management of ifconfig
  41.                 and make a mistake will have no network and a bundle
  42.                 or error. Back to square one. The purpose of netconf
  43.                 is to make sure  everything works...
  44.  
  45.                 At least, netconf will print a message
  46.                 in the log as a remainder that if it was
  47.                 allowed, netconf would have done this
  48.                 and this.
  49.             */
  50.             ret = 0;
  51.             if (!simul_ison()){
  52.                 net_prtlog (MSG_U(X_WOULDHAVE,"Would have %s %s\n")
  53.                     ,go ? MSG_U(X_STARTED,"started")
  54.                         : MSG_U(X_STOPPED,"stopped")
  55.                     ,name);
  56.             }
  57.         }else{
  58.             if (go){
  59.                 ret = dae->startif();
  60.             }else{
  61.                 ret = dae->stop();
  62.             }
  63.         }
  64.     }
  65.     return ret;
  66. }
  67. /*
  68.     Establish a run level by starting, restarting or stopping some
  69.     daemon.
  70. */
  71. void netconf_runlevel(
  72.     int level)        // 0 = Minimal local service (loopback)
  73.                     // 1 = Basic client mode
  74.                     // 2 = full client/server mode
  75.                     // -1 == use the same as the last time
  76.                     // This is used by netconf --update
  77. {
  78.     /*# Specification: netconf / setting runlevel / timeout on msgs
  79.         When netconf activate the different networking services
  80.         and other, it may generate different error message.
  81.         A timeout of 15 seconds is established. If there is
  82.         no operator, netconf will continue by itself.
  83.  
  84.         This avoid to have a server with a small configuration
  85.         problem failing to reboot because it wait for a
  86.         single <enter>
  87.     */
  88.     dialog_settimeout (15,MENU_ESCAPE,true);
  89.     /* #Specification: crond
  90.         netconf make sure that crond is active (unless told
  91.         no to do so). This is not really related to networking
  92.         but since netconf manage almost all other daemons
  93.         in the system, why not doing it there.
  94.         
  95.         Currently, it checks that crond is running and that's all.
  96.         I am not aware of any reason (beside maintenance mode maybe)
  97.         why crond would have to be shutdown or restart or signaled.
  98.         So netconf only check it is active.
  99.     */
  100.     modules_check();
  101.     netconf_startstop ("crond",1);
  102.     /* #Specification: hostname / must be set
  103.         If the hostname can't be set, the rest of the networking won't
  104.         be activated. A message is printed, but nothing can be started.
  105.     */
  106.     fstab_checkmount (1);
  107.     fixperm_check();
  108.     lilo_update();
  109.     char msg[10000];
  110.     if (netconf_netok(msg)==NULL
  111.         || netconf_sethostname() == -1){
  112.         xconf_error (MSG_U(E_IVLBASIC
  113.             ,"Invalid basic configuration of the host\n%s\n")
  114.             ,msg);
  115.     }else{
  116.         if (level != -1){
  117.             netconf_setnetlevel(level);
  118.         }else{
  119.             level = netconf_getnetlevel();
  120.         }
  121.         netconf_setloopback();
  122.         alias_setup("lo");    // See below
  123.         netconf_startstop ("rpc.portmap",1);
  124.         netconf_startstop ("inetd",1);
  125.         netconf_startstop ("syslogd",1);
  126.         netconf_startstop ("klogd",1);
  127.         netconf_startstop ("lpd",1);
  128.         /* #Specification: module / probing
  129.             We let the modules do something at 4 different places
  130.             during the probing for configuration changes.
  131.  
  132.             #
  133.             At the end of the probing for local mode
  134.             At the end of the client mode
  135.             At the end of the server mode
  136.             #
  137.         */
  138.         module_probe (0,level);
  139.         if (level > 0){
  140.             netconf_setdevices();
  141.             ipx_set();
  142.             route_install();
  143.             netconf_startstop ("routed",1);
  144.             netconf_startstop ("gated",1);
  145.             netconf_startstop ("named",1);
  146.             if (dns_ping()!=-1){
  147.                 netconf_startstop ("ypbind",1);
  148.                 /* #Specification: netconf / datetime / updating
  149.                     if configured, datetime_getfromnet() always
  150.                     perform an action. We avoid doing it while
  151.                     in simulation mode as it gives
  152.                     the impression the system is never in sync
  153.                     with its configuration.
  154.                     
  155.                     "netconf --status" would always complain.
  156.                 */
  157.                 if (!simul_ison()) datetime_getfromnet();
  158.                 netconf_startstop ("amd",1);
  159.                 fstab_checkmount (0);
  160.                 netconf_startstop ("sendmail",1);
  161.                 module_probe (1,level);
  162.                 if (level > 1){
  163.                     /* #Specification: netconf / aliases / activating
  164.                         IP aliases are only activated in server mode.
  165.                         I don't see much usage for it in another mode.
  166.                         They are not disactivated when going back in client
  167.                         mode though.
  168.  
  169.                         There is a small exception. The alias for
  170.                         the loopback device are always activated. If someone
  171.                         setup an alias on "lo", better activate it when "lo"
  172.                         is.
  173.                     */
  174.                     alias_setup();
  175.                     netconf_startstop ("rpc.nfsd",1);
  176.                     netconf_startstop ("rpc.mountd",1);
  177.                     netconf_startstop ("sshd",1);
  178.                     rarp_activate();
  179.                     module_probe (2,level);
  180.                 }else{
  181.                     netconf_startstop ("rpc.nfsd",0);
  182.                     netconf_startstop ("rpc.mountd",0);
  183.                 }
  184.                 firewall_setup();
  185.             }
  186.         }else{
  187.             netconf_startstop ("sendmail",0);
  188.             netconf_startstop ("gated",0);
  189.             netconf_startstop ("routed",0);
  190.             netconf_startstop ("amd",0);
  191.             netconf_startstop ("rpc.nfsd",0);
  192.             netconf_startstop ("rpc.mountd",0);
  193.         }
  194.     }
  195.     dialog_settimeout (0,MENU_ESCAPE,false);
  196. }
  197.  
  198.